//
//  HMRecommendListCell.m
//  HowToDo
//
//  Created by Stan on 2017-01-03.
//  Copyright © 2017 KY. All rights reserved.
//

#import "HMRecommendListCell.h"
#import "HMShoppingCarTool.h"
#import "HMShoppingCarBtn.h"



@interface HMRecommendListCell ()

///购物车的按钮
@property(strong,nonatomic)HMShoppingCarBtn *shoppingCartBtn;

///封面照片的imageView
@property(strong,nonatomic)UIImageView *coverPhotoImageView;

///标题名字
@property(strong,nonatomic)UILabel *resourceNameLabel;

///简介
@property(strong,nonatomic)UILabel *resourceContentLabel;

///播放时长
@property(strong,nonatomic)UILabel *resourceEnclosureLabel;

///价格
@property(strong,nonatomic)UILabel *priceLabel;

//资源ID
@property(copy,nonatomic)NSString * resourceID;


@end


static CGFloat defaultMargin11 = 11.0;
static CGFloat defaultMargin8 = 8.0;
static CGFloat defaultMargin17 = 17.0;
@implementation HMRecommendListCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self creatCellUI];
    }
    return self;
}

- (void)creatCellUI{
    

    
    //    设置封面照片
    self.coverPhotoImageView = [[UIImageView alloc]init];
    [self.contentView addSubview:self.coverPhotoImageView];
    
    
    self.coverPhotoImageView.image = [UIImage imageNamed:@"201612271441573272"];
    self.coverPhotoImageView.contentMode = UIViewContentModeScaleToFill;
    
    
    [self.coverPhotoImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView.mas_top).offset(defaultMargin11);
        make.left.equalTo(self.contentView.mas_left).offset(defaultMargin11);
        make.bottom.equalTo(self.contentView.mas_bottom).offset(-defaultMargin11);
        make.width.offset(71);
        make.height.mas_lessThanOrEqualTo(98);
        
    }];
    
    
    //    设置标题
    self.resourceNameLabel = [UILabel hm_labelWithText:@"怎么理解适时四驱" fontSize:k_FONT_BIG color:[UIColor blackColor]];
    [self.contentView addSubview:self.resourceNameLabel];
    
    
    
    [self.resourceNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView.mas_top).offset(defaultMargin17);
        make.left.equalTo(self.coverPhotoImageView.mas_right).offset(defaultMargin17);
        make.right.equalTo(self.contentView.mas_right).offset(- defaultMargin17);
        
    }];
    
    //    设置简介
    self.resourceContentLabel = [UILabel hm_labelWithText:@"怎么理解适时四驱" fontSize:k_FONT_NORMAL color:[UIColor blackColor]];
    [self.contentView addSubview:self.resourceContentLabel];
    
    
    [self.resourceContentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.resourceNameLabel.mas_bottom).offset(defaultMargin8);
        make.left.equalTo(self.resourceNameLabel.mas_left).offset(0);
        make.right.equalTo(self.contentView.mas_right).offset(- defaultMargin8);
        
    }];
    
    
    //    设置播放时长
    self.resourceEnclosureLabel = [UILabel hm_labelWithText:@"音频时长：00分00秒" fontSize:k_FONT_SMALL colorWithHex:0xb8b8b8];
    [self.contentView addSubview:self.resourceEnclosureLabel];
    
    
    [self.resourceEnclosureLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.resourceContentLabel.mas_bottom).offset(defaultMargin8);
        make.left.equalTo(self.resourceNameLabel.mas_left).offset(0);
        
    }];
    
    
    //    设置价格
    self.priceLabel = [UILabel hm_labelWithText:@"¥1" fontSize:k_FONT_SMALL colorWithHex:0xff9300];
    [self.contentView addSubview:self.priceLabel];
    
    
    [self.priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.resourceNameLabel.mas_left).offset(0);
        make.bottom.equalTo(self.contentView.mas_bottom).offset(-defaultMargin17);
        
    }];
    
    //    设置购物车的btn
    self.shoppingCartBtn = [[HMShoppingCarBtn alloc]init];
    [self.contentView addSubview:self.shoppingCartBtn];

    [self.shoppingCartBtn setImage:[UIImage imageNamed:@"add_tochat_btn"] forState:UIControlStateNormal];
    [self.shoppingCartBtn setImage:[UIImage imageNamed:@"add_tochat_btn_incar_44x44_"] forState:UIControlStateSelected];
    
    [self.shoppingCartBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.contentView.mas_bottom).offset(-14);
        make.right.equalTo(self.contentView.mas_right).offset(-20);
    }];
    

    
    [self layoutIfNeeded];
}



- (void)setListModel:(HMHomeRecommendListModel *)listModel{
    _listModel = listModel;
    
    self.resourceID = listModel.resource_id;
    self.resourceNameLabel.text = listModel.resource_name;
    self.resourceContentLabel.text = listModel.resource_content;
    self.resourceEnclosureLabel.text = [NSString getTimeWithString:listModel.resource_enclosure];
    
    [self.coverPhotoImageView sd_setImageWithURL:[NSURL URLWithString:listModel.image_url] placeholderImage:[UIImage imageNamed:@"201612271441573272"]];
    
    //    给购物车的Btn赋值
    self.shoppingCartBtn.resource_id = listModel.resource_id;
    self.shoppingCartBtn.image_url = listModel.image_url;
    self.shoppingCartBtn.resource_name = listModel.resource_name;
    self.shoppingCartBtn.resource_content = listModel.resource_content;
    self.shoppingCartBtn.resource_enclosure = listModel.resource_enclosure;
    self.shoppingCartBtn.price = listModel.price.description;
    }




@end
